<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>添加流程菜单</title>
    <link rel="stylesheet" href="/lib/laydate.css">
    <link rel="stylesheet" href="../../css/sys/menuSetting.css">

    <script src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="../../lib/layer/layer.js?20201106"></script>
    <script src="/js/base/base.js"></script>
    <script src="../../js/common/language.js"></script>
    <script src="/lib/jquery.form.min.js"></script>

    <style>
        .trTextP p {
            margin-bottom: 15px;
        }

        .colo {
            font-size: 13px;
            background: #3791DA;
            color: white;
        }

        .tabfont {
            font-size: 13px;
        }

        .oldtable {
            font-size: 13px;
            background-color: #F6F7F9;
        }

        .eventable {
            font-size: 13px;
            background-color: #FFFFFF;
        }
        #errtable td{
            padding: 5px;
            background-color: #fff;
            font-size: 11pt;
            color: #2F5C8F;
            font-weight: bold;
        }
        .divBtn{
            width: 70px;
            height: 28px;
            background: url("/img/confirm.png") no-repeat;
            line-height: 28px;
            cursor: pointer;
            margin: 10px auto;
        }
        .tabTwo1 td{
            padding: 5px;
            background-color: #fff;
            font-size: 11pt;
            color: #2F5C8F;
            font-weight: bold;
        }

    </style>

</head>
<body>


<div class="content">

    <div class="right" style="width: 100%">
        <div class="AddChild">
    <div class="header">
        <span class="divP" style="margin-left: 30px"><img src="../img/sys/icon_addMainMenuCate.png" style="vertical-align: middle;margin-bottom: 3px;margin-right: 12px;" alt="<fmt:message code="menuSetting.th.AddMenu" />"> 新建工作流菜单</span>
    </div>
    <div class="tab">
        <table cellspacing="0" cellpadding="0" class="tab"
               style="border-collapse:collapse;background-color: #fff;width:75%;">
            <tr>
                <td width="25%"><fmt:message code="menuSetting.th.ID" />：</td>
                <td width="70%">
                    <input type="text" name="addfId" value="">

                    <p style="font-size: 12px;"><fmt:message code="menuSetting.th.description1" /></p>
                </td>
            </tr>
            <tr>
                <td width="25%"><fmt:message code="menuSetting.th.menud" />：</td>
                <td width="70%">
                    <select name="addParentId" id="menuTree" style="width: 204px;">
                    </select>
                </td>
            </tr>
            <tr>
                <td width="25%"><fmt:message code="menuSetting.th.itemCode" />：</td>
                <td width="70%">
                    <input type="text" name="addId" value=""  onblur="checkAddId()">
                    <span id="checkAddIdspan"></span>
                    <p style="font-size: 12px;"><fmt:message code="workflow.th.description2" /></p>
                </td>
            </tr>
            <tr>
                <td width="25%"><fmt:message code="workflow.th.descdrg" /></td>
                <td width="70%">
                    <input type="text" name="addName" value="">
                </td>
            </tr>
            <tr>
                <td width="25%"><fmt:message code="workflow.th.module" />：</td>
                <td width="70%">
                    <input type="text" name="addUrl" value="">
                    <input type="checkbox" name="check" id="newChecked" value="0">
                    <span style="font-size: 12px;"><fmt:message code="workflow.th.mode" /></span>
                </td>
            </tr>
            <tr>
                <td width="25%">传递加密后的用户信息：</td>
                <td width="70%">
                    <select name="addSendUser" id="addSendUser">
                        <option value="0">关闭</option>
                        <option value="1">开启</option>
                    </select>
                    <%--<span style="font-size: 12px;">如果选择开启,子菜单模块路径必须包含http</span>--%>
                </td>
            </tr>
            <tr>
                <td width="25%">密钥：</td>
                <td width="70%">
                    <input type="text" name="addSendKey" value="">
                    <%--<span style="font-size: 12px;">开启后生效</span>--%>
                </td>
            </tr>
            <tr>
                <td width="25%">是否在app中显示本菜单：</td>
                <td width="70%">
                    <input type="radio" name="addisShowFunc" value="0" checked>
                    <span style="font-size: 12px;">是</span>
                    <input type="radio" name="addisShowFunc" value="1" >
                    <span style="font-size: 12px;">否</span>
                </td>
            </tr>
            <tr class="trTextP">
                <td colspan="2">
                    <p style="font-size: 12px;font-weight: bold;"><fmt:message code="workflow.th.definition" />:</p>

                    <p><span style="font-size: 12px;font-weight: bold;"><fmt:message code="workflow.th.defi" />：</span><span
                            style="font-size: 12px;"><fmt:message code="workflow.th.dscrib" />。</span>
                    </p>

                    <p><span style="font-size: 12px;font-weight: bold;"><fmt:message code="workflow.th.numu" />：</span><span
                            style="font-size: 12px;"><fmt:message code="workflow.th.hyui" /></span>

                    </p>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="div_btn">
                        <input type="button" class="inpuBtn backOkBtn" id="btn_sure"
                               value="&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message code="global.lang.ok" />"/>
                        <input type="button" class="inpuBtn backCanBtn" id="btn_back"
                               value="&nbsp;&nbsp;&nbsp;&nbsp;重选"/>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
    </div>
</div>


<script type="application/javascript">
$(function(){
    // 弹窗选择
    selectMenuType();
    // 获取menuId
    getChildId();
    // 获取所有菜单
    selectMenu($('#menuTree'));

    //新建子菜单确定按钮
    $('#btn_sure').click(function () {
        var id = $('.refresh').parents('tr').attr('childId')
        addChildMenu(id, $('.childMenu'));
    });

    //新建子菜单重选按钮
    $('#btn_back').click(function () {
        selectMenuType()
    })



});

function selectMenuType() {
    var flowId = $.GetRequest().flowId;
    layer.open({
        type: 1,
        title:['选择添加的流程菜单类型', 'background-color:#2b7fe0;color:#fff;'],
        area: ['400px', '200px'],
        shadeClose: false, //点击遮罩关闭
        content:
            '<table class="select_table" style="margin:0 auto;">' +
                '<tr style="margin-top: 10px;height: 60px"><td><input type="radio" name="menuType" value="todo" id="todoType" ><label for="todoType">待办工作（包括新建）</label></td></tr>'+
                '<tr style="margin-top: 10px"><td><input type="radio" name="menuType" value="query" id="queryType" ><label for="queryType">查询工作</label></td></tr>'+
            '</table>',
        btn: ['确定','取消'],
        btn1: function (index) {
            var menuType = $('input[name=menuType]:checked').val();
            if(menuType == 'todo'){
                $('input[name=addName]').val("待办工作");
                $('input[name=addUrl]').val("workflow/work/workList?flowId="+flowId);
            } else if(menuType='query') {
                $('input[name=addName]').val("查询工作");
                $('input[name=addUrl]').val("flowRunPage/queryFlowRun?flowId="+flowId);
            }
            layer.closeAll();
        },
    });

}

function selectMenu(element) {
    $.ajax({
        type: 'get',
        url: '../showNewMenu',
        dataType: 'json',
        success: function (rsp) {
            var data = rsp.datas;
            var str = '';
            str = queryMenuT(data, str)
            element.append(str);
        }
    })
}

function queryMenuT(data, str) {
    for (var i = 0; i < data.length; i++) {
        if (data[i].id.length==2){
            str += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
        }else{
            str += '<option value="' + data[i].id + '">' +"&nbsp;&nbsp;├"+data[i].name + '</option>';
        }

        if (data[i].child) {
            if (data[i].child.length > 0) {
                str = queryMenuT(data[i].child, str);
            }
        }

    }
    return str;
}

function getChildId(){
    $.ajax({
        type:'get',
        url:'../getMenuId',
        dataType:'json',
        success:function(res){
            var data=res.object;
            $('input[name="addfId"]').val(data);
            $('input[name="addId"]').val('');
            $('input[name="addName"]').val('');
            $('input[name="addUrl"]').val('');
        }
    })
}

function addChildMenu(id, element) {
    var data = {
        'fId': $('input[name="addfId"]').val(),
        'parentId': $('select[name="addParentId"] option:checked').val(),
        'id': $('input[name="addId"]').val(),
        'name': $('input[name="addName"]').val(),
        'url': $('input[name="addUrl"]').val(),
        'isopenNew': $('#newChecked').val(),
        'sendUser': $('select[name="sendUser"] option:checked').val(),
        'sendKey': $('input[name="sendKey"]').val(),
        'isShowFunc': $('input[name="addisShowFunc"]:checked').val()
    }
    var reg = /^\d{2}$/;
    var valId = reg.test($('input[name="addId"]').val());
    if (valId) {
        $.ajax({
            type: 'post',
            url: '../addFunction',
            dataType: 'json',
            data: data,
            success: function (rsp) {
                if (rsp.flag == true) {
                    $.layerMsg({content: depatement_th_Newsuccessfully, icon: 1}, function () {
                        $('.monoidalSet').show().siblings().hide();
                        getChildId();
                    });
                } else {
                    $.layerMsg({content: depatement_th_Newfailed, icon: 2}, function () {
                        $('.monoidalSet').show().siblings().hide();
                    });
                }
                // $('.monoidalSet').show().siblings().hide();
                // twoLevelMenu(id,element);
            }
        })
    } else {
        $.layerMsg({content: "输入字段不符合，重新输入", icon: 0}, function () {
            return false;
        });
    }

}

</script>
</body>
</html>
